﻿using Bilibili.Model.Common;
using Bilibili.WebClient;
using LibVLCSharp.Shared;
using System;
using System.IO;

namespace Avalonia.BiliBili.Libs.Medias
{
    public sealed class MediaItem : LibVLCSharp.Shared.Media
    {
        private const string DEFAULT_USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36";
        public MediaItem(MediaList mediaList) : base(mediaList) { }
        public MediaItem(LibVLC libVLC, Uri uri, params string[] options) : base(libVLC, uri, options) { }
        public MediaItem(LibVLC libVLC, string mrl, FromType type = FromType.FromPath, params string[] options) : base(libVLC, mrl, type, options) { }
        public void SetHeader(DataSourceHeader sourceHeader)
        {
            var referer = sourceHeader == null ? Current.HOST : sourceHeader.Referer;
            SetHeader(referer);
        }
        public void SetHeader(string referer)
        {
            AddOption($":http-referrer={referer}");
            AddOption($":http-origin={Current.HOST}");
            AddOption($":http-user-agent={DEFAULT_USER_AGENT}");
        }
        public void AddSubtitle(FileInfo file)
        {
            if (file != null)
            {
                var uri = new Uri($"file:///{file.FullName}");
                AddSlave(MediaSlaveType.Subtitle, 4, uri);
            }
        }
    }
}